<?php
namespace app\index\model;

use think\Model;

class Lock extends Model
{   

	/**
     * 根据二维码的编号获取该锁的信息
     *
     * @param string $number 必填, 二维码编号信息
     * @return Boolean
     */
	public function getLockInfo($number){

        $lock_info =  db('lock')->where('number',$number)->find();
        $club_id                  = db('box')->where('id',$lock_info['box_id'])->value('club_id');
        $lock_info['club_number'] = db('club')->where('id',$club_id)->value('club_number');
        return $lock_info;
	}

	/**
     * 将该锁与扫码的用户进行绑定，修改锁的状态为正在使用中
     *
     * @param int $lock_id 必填,锁得id
     * @param int $user_id 必填，用户的id
     * @return Boolean
     */

	public function updateLockUsingStatus($lock_id,$user_id){
        $update_info['status']  = 1;
        $update_info['user_id'] = $user_id;
        $update_info['is_pass'] = 0;
        return db('lock')->where('id',$lock_id)->update($update_info) ? 1 : 0;
	}

	/**
     * 用户关锁，即用户还杆操作
     *
     * @param int $number 必填 二维码的编号
     * @param int $user_id 必填，用户的id
     * @return Boolean
     */
	public function userReturnBallArm($number){
		$where['number']  = $number;
        //$where['user_id'] = $user_id;
        $update_info['status']  = 0;
        $update_info['user_id'] = '';
        db('lock')->where('number',$number)->update($update_info);
	}
}